﻿package mortal.game.view.shopMall.view
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.shopMall.data.*;

    public class ShopCommonPanel extends GSprite
    {
        protected var _goodsList:GTileList;
        protected var _pageSelecter:PageSelecter;
        protected var _tshop:TShop;
        protected var _curShopTabData:ShopTabData;

        public function ShopCommonPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._goodsList = UIFactory.tileList(15, -5, 800, 480, this);
            this._goodsList.columnWidth = 240;
            this._goodsList.rowHeight = 104;
            this._goodsList.horizontalGap = 8;
            this._goodsList.verticalGap = 5;
            this._goodsList.setStyle("cellRenderer", GoodsCellRenderer);
            this._goodsList.isClickedUpdate = false;
            this._goodsList.isChangeUpdate = false;
            this._goodsList.isClickedUpdate = false;
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(267, 450, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._pageSelecter.currentPage = 1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._goodsList.dispose(param1);
            this._goodsList = null;
            this._pageSelecter.dispose(param1);
            this._pageSelecter = null;
            this._tshop = null;
            this._curShopTabData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.getItemsByTab(this._tshop.code);
            return;
        }// end function

        protected function updatePageSelecter() : void
        {
            var _loc_1:int = 0;
            if (this._curShopTabData)
            {
                _loc_1 = this._curShopTabData.showItemNum;
            }
            else
            {
                _loc_1 = ShopUtil.getShopMallTabObjByShopCode(this._tshop.code).showItemNum;
            }
            this._pageSelecter.maxPage = Math.ceil(ShopConfig.instance.getShopSellItemByShopCode(int(this._tshop.code)).length / _loc_1);
            return;
        }// end function

        protected function set tshop(param1:TShop) : void
        {
            this._tshop = param1;
            return;
        }// end function

        public function getItemsByTab(param1:int, param2:int = 0, param3:int = -1) : void
        {
            this.tshop = ShopConfig.instance.getTShopByCode(param1);
            if (this._goodsList)
            {
                this._goodsList.dataProvider = this.getBuyDataProvider(param1, this._pageSelecter.currentPage, param2);
                this._goodsList.selectedIndex = param3;
                this.updatePageSelecter();
            }
            return;
        }// end function

        public function getItemsByTabAndPage(param1:int, param2:int, param3:int = 0, param4:int = -1) : void
        {
            this.tshop = ShopConfig.instance.getTShopByCode(param1);
            if (this._goodsList)
            {
                this._goodsList.dataProvider = this.getBuyDataProvider(param1, param2, param3);
                this._goodsList.selectedIndex = param4;
                this.updatePageSelecter();
            }
            return;
        }// end function

        protected function getBuyDataProvider(param1:int, param2:int, param3:int) : DataProvider
        {
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:ShopItemData = null;
            var _loc_11:Object = null;
            var _loc_4:* = new DataProvider();
            var _loc_5:* = ShopConfig.instance.getShopSellItemByShopCode(int(param1));
            this._curShopTabData = ShopUtil.getShopMallTabObjByShopCode(param1);
            var _loc_6:* = this._curShopTabData.showItemNum;
            if (_loc_5)
            {
                _loc_7 = _loc_6 * (param2 - 1);
                if (_loc_6 * param2 <= _loc_5.length)
                {
                    _loc_8 = _loc_6 * param2;
                }
                else
                {
                    _loc_8 = _loc_5.length;
                }
                _loc_9 = _loc_7;
                while (_loc_9 < _loc_8)
                {
                    
                    _loc_10 = new ShopItemData(_loc_5[_loc_9]);
                    _loc_11 = {data:_loc_10, type:param3};
                    _loc_4.addItem(_loc_11);
                    _loc_9++;
                }
            }
            return _loc_4;
        }// end function

        public function updateMoney(param1:Object = null) : void
        {
            return;
        }// end function

    }
}
